Repository navigation
fix(mcp): read cost totals from the analytics summary - #15355
Merged
diegosouzapw merged 1 commit intoOct 6, 2026
Merged
Conversation
The usage analytics route returns totals under `summary` and only honours a `range` query param. Five MCP handlers read `totalCost`, `requestCount` and per-provider latency from the top level and passed `period=session`, which the route ignores, so every cost and request count they reported was zero while the byProvider breakdown stayed correct. A single reader now knows the real shape: totals come from `summary`, a provider's request count, latency and success rate are aggregated from its `byModel` rows, and a report period maps onto the range values the route accepts. A missing figure is zero, not a healthy default. pickFastestModel still reads p95, error rate, tokens per second, time to first token and latency standard deviation, which the analytics route does not return at all. Only its query param is corrected here. Signed-off-by: Minxi Hou <houminxi@gmail.com>
diegosouzapw
merged commit Oct 6, 2026
489428b
into
diegosouzapw:release/v3.8.52
43 of 51 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
totalCost: 0andrequestCount: 0even though thebyProviderbreakdown was correct and summed to a real total./api/usage/analyticsreturns its totals undersummaryand only honours arangequery parameter. The handlers readtotalCost,requestCountand per-provider latency from the top level, where those fields do not exist, and passedperiod=session, which the route ignores.summary. A provider's request count, latency and success rate are aggregated from itsbyModelrows. A report period maps onto therangevalues the route accepts. A missing figure is zero.pickFastestModelasked for the same ignoredperiodparameter. Its query is corrected. It also reads p95 latency, error rate, tokens per second, time to first token and latency standard deviation, which the analytics route does not return at all. Those stay at zero until the route computes them.Related Issues
Validation
node --import tsx/esm --test tests/unit/mcp-analytics-shape.test.ts(5 pass)eslinton the changed files, with the repo suppression filerelease/v3.8.52@69cb18dca8totalsinstead ofsummaryturns 1 of the 5 tests red, and the change was revertedTests Added Or Updated
tests/unit/mcp-analytics-shape.test.ts(added)Coverage Notes
readAnalyticsTotals,readProviderMetricsandanalyticsRangeForPeriodwith the response shape/api/usage/analyticsactually returns, including the empty-payload case that yields zeros.Reviewer Notes
handleGetProviderMetricsused to fall back to a success rate of1.0when the field was missing, which reported "no data" as "100% success". It now reports0. That is deliberate.p50LatencyMs,p95LatencyMsandp99LatencyMsin the provider metrics, and the five speed fields inpickFastestModel, are read from the top level because the analytics route does not compute them. Fixing those means extending the route, which is out of scope here.